package com.java.zhuiyun.api.userAchievement.service.impl;

import com.java.zhuiyun.api.playerinformation.mapper.PlayerInformationMapper;
import com.java.zhuiyun.api.userAchievement.model.UserAchievementModel;
import com.java.zhuiyun.common.errorCode.EmErrorCode;
import com.java.zhuiyun.common.response.CommonResult;
import com.java.zhuiyun.api.userAchievement.entity.UserAchievement;
import com.java.zhuiyun.api.userAchievement.mapper.UserAchievementMapper;
import com.java.zhuiyun.api.userAchievement.service.UserAchievementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName UserAchievementServiceImpl
 * @Description TODO 用户成就管理服务类
 * @Author WX
 * @Date 2023/10/16 13:54
 **/
@Service
public class UserAchievementServiceImpl implements UserAchievementService {
    @Autowired
    private UserAchievementMapper userAchievementMapper;

    @Autowired
    private PlayerInformationMapper playerInformationMapper;

    /*
     * @Author WX
     * @Description 根据openid查询用户的成就信息
     * @Date 2023/10/16 14:07
     * @Return
     * @param openid
     */
    @Override
    public CommonResult selectUserAchievement(int uid) {
        List<UserAchievementModel> list = userAchievementMapper.selectUserAchievement(uid);
        return CommonResult.ok(list);
    }

    /*
     * @Author WX
     * @Description 领取奖励操作
     * @Date 2023/10/17 8:25
     * @Return
     * @param id
     */
    @Override
    public CommonResult claimRewardOperation(int id) {
        // 添加经验积分
        int a = playerInformationMapper.updateExperienceAndPoints(id);

        // 领取奖励修改状态
        int i = userAchievementMapper.claimRewardOperation(id);
        if (i > 0) {
            return CommonResult.ok(EmErrorCode.UPDATE_OK);
        }else {
            return CommonResult.ok(EmErrorCode.UPDATE_ERROR);
        }
    }
}
